package com.xlp.drink;

import com.xlp.additive.Additive;
import com.xlp.additive.MilkCap;

import java.util.ArrayList;
import java.util.List;

public class CustomDrink implements Drink{
    private Drink drink;
    private List<Additive> additives = new ArrayList<>();

    public CustomDrink(Drink drink){
        setDrink(drink);
    }

    public Drink getDrink() {
        return drink;
    }

    public void setDrink(Drink drink) {
        if (drink == null)
            throw new IllegalArgumentException("必须点一份饮料！");
        this.drink = drink;
    }

    public List<Additive> getAdditives() {
        return additives;
    }

    public void setAdditives(List<Additive> additives) {
        if (additives != null)
            this.additives = additives;
    }

    public boolean addAdditive(Additive additive){
        if (additive == null) return false;
        return additives.add(additive);
    }
    
    /**
     * 饮料价格
     *
     * @return 价格
     */
    @Override
    public double getPrice() {
        double sumPrice = drink.getPrice();
        for (Additive additive : additives) {
            sumPrice += additive.getPrice();
        }
        return sumPrice;
    }

    /**
     * 饮料名称
     *
     * @return 名称
     */
    @Override
    public String getName() {
        StringBuilder name = new StringBuilder(drink.getName());
        for (Additive additive : additives) {
            name.append(" + ").append(additive.getName());
        }
        return name.toString();
    }
}
